
// get http object to handle requests
var http = getHTTPObject();

function getHTTPObject() {
	  var xmlhttp;
	  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	    try {
	      xmlhttp = new XMLHttpRequest();
	      xmlhttp.overrideMimeType("text/xml"); 
	    } catch (e) {
	      xmlhttp = false;
	    }
	  }
	  return xmlhttp;
	}

function getURLParameters() {
    var sURL = window.document.URL.toString();  
    if (sURL.indexOf("?") > 0)
    {
       var arrParams = sURL.split("?");         
       var arrURLParams = arrParams[1].split("&");      
       var arrParamNames = new Array(arrURLParams.length);
       var arrParamValues = new Array(arrURLParams.length);     
       var i = 0;
       for (i=0;i<arrURLParams.length;i++)
       {
        var sParam =  arrURLParams[i].split("=");
        arrParamNames[i] = sParam[0];
        if (sParam[1] != "")
            arrParamValues[i] = unescape(sParam[1]);
        else
            arrParamValues[i] = "No Value";
       }

       for (i=0;i<arrURLParams.length;i++)
       {
                if(arrParamNames[i] == "uname"){
                return arrParamValues[i];
             }
       }
       return "No Parameters Found";
    }
}

function login(){
	  var xhr = new XMLHttpRequest();
	    xhr.onreadystatechange = function() {
	        if (xhr.readyState == 4) {
	            var data = xhr.responseText;
	            alert(data);
	        }
	    }
	    xhr.open('GET', 'procardioServlet.do', true);
	    xhr.send(null);
}

function login3() {
	var userName = document.getElementById("name").value;
	var password = document.getElementById("password").value;
	debugger;
	 $.ajax({
         type: "POST",
         url: "procardioServlet.do",
         data: {userName: userName,password: password },
         dataType: "json",
         
         //if received a response from the server
         success: function( data, textStatus, jqXHR) {
             //our country code was correct so we have some information to display
        	 alert(data);
        	 debugger;
              if(data.success){
            	  alert(data);
              } 
              //display error message
              else {
                  alert("gresut");
              }
         },
         
         //If there was no resonse from the server
         error: function(jqXHR, textStatus, errorThrown){
              console.log("Something really bad happened " + textStatus);
               $("#ajaxResponse").html(jqXHR.responseText);
         },
         
      });

}



function loginvechi() {
			var userName = document.getElementById("name").value;
			var password = document.getElementById("password").value;
			debugger;
			$.ajax({
					url: "procardioServlet.do",
					type: "POST",
					data: { userName: userName, password: password},
					success: function (response) {
							alert(response);
							var uName = document.getElementById("name");
							var scoreText = document.getElementById("password");
							uName.value = "User name";
							scoreText.value = "Password ";
							
					}
				});
	}

/*
 * creates a new XMLHttpRequest object which is the backbone of AJAX,
 * or returns false if the browser doesn't support it
 */
function getXMLHttpRequest() {
  var xmlHttpReq = false;
  // to create XMLHttpRequest object in non-Microsoft browsers
  if (window.XMLHttpRequest) {
    xmlHttpReq = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      // to create XMLHttpRequest object in later versions
      // of Internet Explorer
      xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (exp1) {
      try {
        // to create XMLHttpRequest object in older versions
        // of Internet Explorer
        xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (exp2) {
        xmlHttpReq = false;
      }
    }
  }
  return xmlHttpReq;
}
/*
 * AJAX call starts with this function
 */
function login1() {
  var xmlHttpRequest = getHTTPObject();
  xmlHttpRequest.onreadystatechange = getReadyStateHandler(xmlHttpRequest);
  xmlHttpRequest.open("POST", "procardioServlet.do", true);
  xmlHttpRequest.setRequestHeader("Content-Type",
      "application/x-www-form-urlencoded");
  xmlHttpRequest.send(null);
}
 
/*
 * Returns a function that waits for the state change in XMLHttpRequest
 */
function getReadyStateHandler(xmlHttpRequest) {
 
  // an anonymous function returned
  // it listens to the XMLHttpRequest instance
  return function() {
    if (xmlHttpRequest.readyState == 4) {
      if (xmlHttpRequest.status == 200) {
        alert(xmlHttpRequest.responseText);
      } else {
        alert("HTTP error " + xmlHttpRequest.status + ": " + xmlHttpRequest.statusText);
      }
    }
  };
}